<!--
 * @Author: H.
 * @Date: 2021-12-06 18:12:03
 * @LastEditTime: 2021-12-07 15:21:36
 * @Description:
-->
<template>
  <div class="nav-header">
    <div>
      <el-icon @click="handleFoldClick">
        <i-fold v-if="isFold" class="fold-menu" />
        <i-expand v-else class="fold-menu" />
      </el-icon>
    </div>

    <div class="content">
      <HyBbreadcrumb :breadcrumbs="breadcrumbs" />
      <user-info></user-info>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, computed } from 'vue'
import UserInfo from './user-info.vue'
import HyBbreadcrumb from '@/base-ui/breadcrumb'
import { pathMapBreadcrumbs } from '@/utils/map-menus'
import { useStore } from '@/store'
import { useRoute } from 'vue-router'
export default defineComponent({
  emits: ['foldChange'],
  setup(props, context) {
    let isFold = ref(false)
    const handleFoldClick = () => {
      isFold.value = !isFold.value
      context.emit('foldChange', isFold.value)
    }

    // 面包屑的数据
    const store = useStore()
    const route = useRoute()

    // 路径发生变化时需要再次执行pathMapBreadcrumbs，使用computed
    const breadcrumbs = computed(() => {
      const userMenus = store.state.login.userMenus
      const currentPath = route.path
      return pathMapBreadcrumbs(userMenus, currentPath)
    })
    return {
      handleFoldClick,
      isFold,
      breadcrumbs
    }
  },
  components: {
    UserInfo,
    HyBbreadcrumb
  }
})
</script>

<style lang="scss" scoped>
.nav-header {
  width: 100%;
  display: flex;
  .fold-menu {
    font-size: 30px;
    cursor: pointer;
  }
  .content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
    padding-left: 30px;
  }
}
</style>
